<?php
	/*
	 * File: update_page.php
	 * Last modification: 21.07.2011
	 * Author(s): kivio.wanderley
	 * 
	 */
?>

<?php /** UPPER PHP CODE */
	$t_type_option = gpc_get_string('type_option_list', null);

	if(!isset($t_type_option)) {
		echo "Escolha o tipo de registro a ser atualizado.";
		return;
	}
?>

<!-- SELECT OPTIONS FOR TYPES -->

<form action="main_page.php?page=update_page" method="post">
<table>
<tr>
	<td>
	<?php 
		# Choose for PAGE 3 show
		
		if( $t_type_option == "people" ) {
			print_people_option_list( gpc_get_int('type_id'), "type_id" );
		} elseif( $t_type_option == "user" ) {
			print_user_option_list( gpc_get_int('type_id'), "type_id" );
		}
		
	?>
	</td>
	<td><?php print_submit_button('change_button'); ?></td>
	<td><?php if(gpc_get_int('type_id', false)) print_button('remove_button', 'remove_btt'); ?></td>
</tr>
</table>

	<input type="hidden" name="type_option_list" value="<?php echo $t_type_option ?>" />
</form>
	
<!-- REMOVE FORM USED BY THE REMOVE BUTTON -->

<form name="remove_form" id="remove_form" action="core/remove_inc.php" method="post">
	<input type="hidden" name="type_id" value="<?php echo gpc_get_int('type_id') ?>" />
	<input type="hidden" name="remove_type" value="<?php echo $t_type_option ?>" />
</form>

<?php /** PAGES */
	# Verify if option was selected to its update page
	if( gpc_get('type_id', false) ) 
	{
		# Verify type of page
		if($t_type_option == "people") { 			
						echo '<form action="core/update_inc.php" method="post">';
														require('update_page_people.php'); 
						echo '</form>';
														
		} elseif ($t_type_option == "user") {			require('update_page_user.php');  	 
		
		} elseif ($t_type_option == ACCESS_DENIED) { set_info_msg("ACCESS_DENIED", I_WARN);
		} else {									 set_info_msg("UNKNOWN_ERRO", I_ERR);
		}
	}
?>

<script>
	$(document).ready(function () { 
		/* Hide remove button if select list is changed */
		$("#type_id").change( function() {
			$("#remove_btt").hide();
		});
		
		$("#remove_btt").click( function() {
			$("#remove_form").submit();
		});

		/* Enable filed to edit and update */
		$(':checkbox').click(function(){
	        if($('input[name='+ $(this).attr('value')+']').attr('disabled') == false){
	            $('input[name='+ $(this).attr('value')+']').attr('disabled', true);
	        }else{
	            $('input[name='+ $(this).attr('value')+']').attr('disabled', false);
	        }

	        if($('select[name='+ $(this).attr('value')+']').attr('disabled') == false){
	            $('select[name='+ $(this).attr('value')+']').attr('disabled', true);
	        }else{
	            $('select[name='+ $(this).attr('value')+']').attr('disabled', false);
	        }
	    });
	});
</script> 